
<template>
  <div>
    <el-popover placement="bottom-start" :visible-arrow="false" :width="400" trigger="click" v-model="isShowPop" @show="openPop">
      <div class="tips" v-if="sortList.length === 0">
        正在加载中....
      </div>
      <div class="list" v-else>
        <div class="item" @click.stop="handleClick(v)" :class="{active :currentTag.name === v.name   }" v-for=" v  in sortList" :key="v.name">
          {{v.name}}
        </div>
      </div>
      <template #reference>
        <div class="title" slot="reference">
          {{ currentTag.name }} <i class="iconfont icon-arrow-right-bold"></i>
        </div>
      </template>
    </el-popover>

  </div>

</template>

<script>
import { reactive, toRefs } from 'vue'
export default {
  props: {
    currentTag: {
      type: Object,
      default() {
        return {}
      }
    },
    sortList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  setup(p, { emit }) {
    const data = reactive({
      isShowPop: false
    })

    const handleClick = item => {
      data.isShowPop = false
      console.log('item')
      emit('itemBoxClick', item)
    }
    const openPop = () => {
      if (p.sortList.length === 0) {
        emit('getSortList')
      }
    }

    return {
      ...toRefs(data),
      handleClick,
      openPop
    }
  }
}
</script>

<style scoped>
.title {
  padding: 5px 10px;
  border: 1px solid #ddd;
  cursor: pointer;
  border-radius: 20px;
  font-size: 12px;
}
.title i {
  font-size: 12px;
}
.tips {
  width: 100%;
  text-align: center;
}
.list {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  text-align: center;
  justify-content: space-evenly;
  height: 300px;
  overflow-y: auto;
}
.item {
  width: 22%;
  padding: 5px 0;
  margin: 5px 0;
  cursor: pointer;
  border-radius: 15px;
}

.active {
  color: var(--red);
  background: var(--navBg);
}
</style>